Ext.define('PJ.view.submittrainingplanviews.List', {
    extend: 'AM.default.DefaultList',
    alias: ['widget.submittrainingplanviewsList'],
    requires: ['AM.default.DefaultSearchForm',
               'AM.default.DateTime', 
               'AM.default.DefaultDateField',
               'AM.default.DefaultDoubleDateField',
               'AM.default.jsonp.DefaultLoadJsonp',//jsonp加载数据
		       'AM.default.DefaultActiveStateCombo',
		       'PJ.view.submittrainingplanviews.PlanAllPlacesList',//所有该地区的计划名额
		       'AM.default.DateMonth',
		       'PJ.view.trainingprogram.UnitsIssuedList'//已下发单位
               ],
    initComponent: function(){
    	var me= this;
    	this.columns = [{
    		header: '计划编号',
    		dataIndex: 'applyNum',
    		width: 120,
    		renderer: function(value, meta, record){
    			return value;
    		}
    	},{
            header: '培训班名称',
            dataIndex: 'className',
            flex: 1,
            minWidth: 120,
    		renderer: function(value, metaData, record){
    			metaData.style = "white-space:normal;cursor: pointer;color:blue;";
    			metaData.tdAttr = "data-qtip='" + value + "' classId=" + record.get("planId") + " versionState=" + record.get("versionState");
    			return value;
    		},
    		listeners: {
    			click: function(g, clm){
    				var classId = clm.getAttribute("classId");
    				var selectScopeStr = $(document.getElementById("selectScope")).find("option:selected").text();
    				win = Ext.create('PJ.view.submittrainingplanviews.Edit', {
    		        	title: "查看培训计划",
    		            flag:2,
    		        	grid: me,
    		        	isDisable:true,
    		        	planId:classId,
    		        	isReadOnly:true,
    		        	isAdd: false,
    		        	selectScopeStr: selectScopeStr
    		        }).show();
    				var actionName = "load";
    				if(gj_onlineLearning_constant.loadType == "jsonp"){
    					actionName = "loadJsonp";
    				}
    				win.down("form").getForm().doAction(actionName,{
    		    		url:me.store.preUpdateUrl,
    		    		params:{
    		    			planId: classId
    		    		},
    		    		success:function(f,action){
    		    			var data = action.response.responseText;
    		    			var json = gj_onlineLearning_constant.loadType=="ajax" ? Ext.decode(data, true) : action.response;
    		    			var form = win.down('form');	 
    		    			var baseForm = form.getForm();
    		    			baseForm.findField("planId").setValue(json.data.planIdNew);
    		    			//baseForm.findField("classNum").setValue(json.data.classNum);
    		    			//baseForm.findField("classNum_").setValue(json.data.classNum);
    		    		}
    		    	});
    			}
    		}
        },{
            header: '计划调训人数',
            dataIndex: 'planNum',
            width: 110,
            sortable: false,
            renderer: function(value, metaData, record){
            	return value;
            }
        },{
        	header: '学制（天）',
        	dataIndex: 'planDay',
            width: 110,
            sortable: false,
            renderer: function(value, metaData, record){
            	return value;
            }
        }/*,{
        	header: '计划时间',
        	dataIndex: 'planDate',
            width: 110,
            sortable: false,
            renderer: function(value, metaData, record){
            	return value;
            }
        }*/,{
        	header: '计划开始时间',
        	dataIndex: 'startPlanDateStr',
            width: 110,
            sortable: false,
            renderer: function(value, metaData, record){
            	return value;
            }
        },{
        	header: '计划结束时间',
        	dataIndex: 'endPlanDateStr',
            width: 110,
            sortable: false,
            renderer: function(value, metaData, record){
            	return value;
            }
        },{
            header: '反馈状态',
            dataIndex: 'feedbackState',
            renderer: function(v, metaData, record){
                if (v == 2) {
                    return '<span style="color:red;">' + '未反馈' + '</span>';
                }
                else if(v == 1) {
                    return '<span style="color:green;">' + '已反馈' + '</span>';
                }
            },
            width: 70
        }];
    	
        this.store = Ext.create('PJ.'+ prototype +'.submittrainingplanviews.List',{
        	isLoad: true
        });
        this.callParent(arguments);
        this.loadType = gj_onlineLearning_constant.loadType;//加载方式
    },
	//填写意见
    onFillopinionsClick:function(){
		var me = this;
		var record=me.getSelectionModel().getSelection();
    	var classId = record[0].get("planId");
		if(this.getSelectionModel().getCount() > 1){
            Ext.Msg.show({
                title: '提示',
                msg: '操作时只可选中一条记录！',
                icon: Ext.Msg.WARNING,
                buttons: Ext.Msg.OK
            });
        	return;
        }
        var win = Ext.create('PJ.view.submittrainingplanviews.FillOpinions', {
        	title: "填写意见",
            flag:2,
        	grid: me,
        	isDisable:true,
        	classId:classId,
        	isReadOnly:false,
        	coArray: null
        }).show();
        var actionName = "load";
		if(gj_onlineLearning_constant.loadType == "jsonp"){
			actionName = "loadJsonp";
		}
		win.down("form").getForm().doAction(actionName,{
    		url:me.store.preUpdateUrl,
    		params:{
    			planId: classId
    		},
    		success:function(f,action){
    			var data = action.response.responseText;
    			var json = gj_onlineLearning_constant.loadType=="ajax" ? Ext.decode(data, true) : action.response;
    			var form = win.down('form');	 
    			var baseForm = form.getForm();
    			Ext.Ajax.request({
    				url:me.store.classificationOpinionsUrl,
    				params: {
    					typeCode: 'fkyj'
    				},
    				success:function(response){
    					var data1=response.responseText;
    					var json1=Ext.decode(data1,true);
    					if(json1.success){
    						var coArray = json1.data;
    						var classificationOpinions = Ext.getCmp("classificationOpinions");
    						win.coArray = coArray;
    						for(i in coArray){
    							classificationOpinions.add({
        							xtype: 'textareafield',
        			    			fieldLabel: coArray[i].dataName,
        			    			name: 'trainingToInformation',
        			    			height: 46,
        			    			vtype: 'blankTrim',
        			                maxLength: 1000,
        			                maxLengthText: '最多可输入1000个字符！'
        						});
    						}
    					}else{
    						Orchid.alert('提示',json1.msg);
    					}
    				}
    			});
    		}
    	});
	},
	/**
     * 计划名额
     */
    onPlanplacesClick: function(){
		var me = this;
		var record = this.getSelectionModel().getSelection();
		var applyNums=new Array();
		for(i in record){
			applyNums.push(record[i].get("applyNum"));
		}
    	Ext.create('AM.default.DefaultWindowView', {
            title: '查看计划名额',
            height:550,
            width: 650,
            grid: me,
            applyNums:applyNums,
            items: [{
                xtype: 'stpvPlanAllPlacesList'
            }],
            listeners: {
            	close: function(){
            		me.getStore().load();
            	}
            }
        });
	},
	/**
	 * 导出详情及名额
	 */
	onDetailsAndPlacesClick: function(){
		var records = me.getSelectionModel().getSelection();
    	//var classId = Ext.isEmpty(record) ? "" : record[0].get("planId");
    	//me.ifSelect('comparisons', me.store.contrastPlacesUrl, classId, 'searchClassId');
		/*
    	var classIdstr = "";
        for(var i = 0;i<records.length;i++){
        	if(i == records.length-1){
        		classIdstr += "searchClassIds=" + records[i].get("planId");
        	}else{
        		classIdstr += "searchClassIds=" + records[i].get("planId") + "&";
        	}
        }
        */
        var atag = Ext.get("exportResume");
        var exportUrl = me.store.contrastPlacesUrl;
        atag.set({
            "href": exportUrl //+ '?' + classIdstr
        });
        atag.dom.click();
	},
    listeners: {
		selectionchange: function(selModel, selected){
            this.down('#' + this.oldId + "Fillopinions").setDisabled(selected.length === 0);//填写意见
            //this.down('#' + this.oldId + "Planplaces").setDisabled(selected.length === 0);//查看计划名额
            //this.down('#' + this.oldId + "Export").setDisabled(selected.length === 0);//导出
		},
		viewready: function(){
			var me = this;
			this.addDocked([{
				dock: 'top',
				xtype: "searchform",
				columnCount: 3,
				fieldDefaults: {
					labelAlign: 'right',
					labelWidth: 100
				},
				items: [{
					xtype: "textfield",
					fieldLabel: '计划申请编号',
					name: "searchApplyNum",
					maxLength: "50",
					emptyText: "请输入计划申请编号"
				},{
					xtype: "textfield",
					fieldLabel: '培训班名称',
					name: "searchClassName",
					maxLength: "50",
					emptyText: "请输入培训班名称"
				},{
					xtype: "combo",
					fieldLabel: '反馈状态',
					name: "searchFeedbackState",
					store: Ext.create("Ext.data.ArrayStore", {
						fields: ['value', 'text'],
						data: [[1, '已反馈'],[2,'未反馈']]
					}),
					valueField: 'value',
					displayField: 'text',
					editable: false,
					emptyText: "请选择"
				}],
				grid: this
			},{
				xtype: 'toolbar',
				dock: 'top',
				displayInfo: true,
				items: [{
					text: '填写意见',
					iconCls: 'editIco',
					itemId: this.oldId + "Fillopinions",
					disabled: true,
					scope: this,
					handler: this.onFillopinionsClick
				},"-", {
					text: '查看计划名额',
					iconCls: 'planplacesIco',
					itemId: this.oldId + "Planplaces",
					disabled: false,
					scope: this,
					handler: this.onPlanplacesClick
				}/*,"-", {
					text: '导出详情及名额',
					iconCls: 'comparisonsIco',
					itemId: this.oldId + "Export",
					disabled: true,
					scope: this,
					handler: this.onDetailsAndPlacesClick
				}*/,"->", this.countSelectPanel]
			}]);
            // 触发权限过滤事件
            me.fireEvent("permission", this);
		}
    }
});
